<?php
if (session_id() == "") session_start(); // Initialize Session data
ob_start(); // Turn on output buffering
?>
<?php include_once "ewcfg10.php" ?>
<?php include_once "ewmysql10.php" ?>
<?php include_once "phpfn10.php" ?>
<?php include_once "planoperacionesinfo.php" ?>
<?php include_once "usuariosinfo.php" ?>
<?php include_once "plansemanalinfo.php" ?>
<?php include_once "pedidoplangridcls.php" ?>
<?php include_once "userfn10.php" ?>
<?php

//
// Page class
//

$planoperaciones_add = NULL; // Initialize page object first

class cplanoperaciones_add extends cplanoperaciones {

	// Page ID
	var $PageID = 'add';

	// Project ID
	var $ProjectID = "{F232ADC5-E4A2-4026-8F03-D0514C19EE8E}";

	// Table name
	var $TableName = 'planoperaciones';

	// Page object name
	var $PageObjName = 'planoperaciones_add';

	// Page name
	function PageName() {
		return ew_CurrentPage();
	}

	// Page URL
	function PageUrl() {
		$PageUrl = ew_CurrentPage() . "?";
		if ($this->UseTokenInUrl) $PageUrl .= "t=" . $this->TableVar . "&"; // Add page token
		return $PageUrl;
	}

	// Message
	function getMessage() {
		return @$_SESSION[EW_SESSION_MESSAGE];
	}

	function setMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_MESSAGE], $v);
	}

	function getFailureMessage() {
		return @$_SESSION[EW_SESSION_FAILURE_MESSAGE];
	}

	function setFailureMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_FAILURE_MESSAGE], $v);
	}

	function getSuccessMessage() {
		return @$_SESSION[EW_SESSION_SUCCESS_MESSAGE];
	}

	function setSuccessMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_SUCCESS_MESSAGE], $v);
	}

	function getWarningMessage() {
		return @$_SESSION[EW_SESSION_WARNING_MESSAGE];
	}

	function setWarningMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_WARNING_MESSAGE], $v);
	}

	// Show message
	function ShowMessage() {
		$hidden = FALSE;
		$html = "";

		// Message
		$sMessage = $this->getMessage();
		$this->Message_Showing($sMessage, "");
		if ($sMessage <> "") { // Message in Session, display
			if (!$hidden)
				$sMessage = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $sMessage;
			$html .= "<div class=\"alert alert-success ewSuccess\">" . $sMessage . "</div>";
			$_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
		}

		// Warning message
		$sWarningMessage = $this->getWarningMessage();
		$this->Message_Showing($sWarningMessage, "warning");
		if ($sWarningMessage <> "") { // Message in Session, display
			if (!$hidden)
				$sWarningMessage = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $sWarningMessage;
			$html .= "<div class=\"alert alert-warning ewWarning\">" . $sWarningMessage . "</div>";
			$_SESSION[EW_SESSION_WARNING_MESSAGE] = ""; // Clear message in Session
		}

		// Success message
		$sSuccessMessage = $this->getSuccessMessage();
		$this->Message_Showing($sSuccessMessage, "success");
		if ($sSuccessMessage <> "") { // Message in Session, display
			if (!$hidden)
				$sSuccessMessage = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $sSuccessMessage;
			$html .= "<div class=\"alert alert-success ewSuccess\">" . $sSuccessMessage . "</div>";
			$_SESSION[EW_SESSION_SUCCESS_MESSAGE] = ""; // Clear message in Session
		}

		// Failure message
		$sErrorMessage = $this->getFailureMessage();
		$this->Message_Showing($sErrorMessage, "failure");
		if ($sErrorMessage <> "") { // Message in Session, display
			if (!$hidden)
				$sErrorMessage = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $sErrorMessage;
			$html .= "<div class=\"alert alert-error ewError\">" . $sErrorMessage . "</div>";
			$_SESSION[EW_SESSION_FAILURE_MESSAGE] = ""; // Clear message in Session
		}
		echo "<table class=\"ewStdTable\"><tr><td><div class=\"ewMessageDialog\"" . (($hidden) ? " style=\"display: none;\"" : "") . ">" . $html . "</div></td></tr></table>";
	}
	var $PageHeader;
	var $PageFooter;

	// Show Page Header
	function ShowPageHeader() {
		$sHeader = $this->PageHeader;
		$this->Page_DataRendering($sHeader);
		if ($sHeader <> "") { // Header exists, display
			echo "<p>" . $sHeader . "</p>";
		}
	}

	// Show Page Footer
	function ShowPageFooter() {
		$sFooter = $this->PageFooter;
		$this->Page_DataRendered($sFooter);
		if ($sFooter <> "") { // Footer exists, display
			echo "<p>" . $sFooter . "</p>";
		}
	}

	// Validate page request
	function IsPageRequest() {
		global $objForm;
		if ($this->UseTokenInUrl) {
			if ($objForm)
				return ($this->TableVar == $objForm->GetValue("t"));
			if (@$_GET["t"] <> "")
				return ($this->TableVar == $_GET["t"]);
		} else {
			return TRUE;
		}
	}

	//
	// Page class constructor
	//
	function __construct() {
		global $conn, $Language;
		$GLOBALS["Page"] = &$this;

		// Language object
		if (!isset($Language)) $Language = new cLanguage();

		// Parent constuctor
		parent::__construct();

		// Table object (planoperaciones)
		if (!isset($GLOBALS["planoperaciones"]) || get_class($GLOBALS["planoperaciones"]) == "cplanoperaciones") {
			$GLOBALS["planoperaciones"] = &$this;
			$GLOBALS["Table"] = &$GLOBALS["planoperaciones"];
		}

		// Table object (usuarios)
		if (!isset($GLOBALS['usuarios'])) $GLOBALS['usuarios'] = new cusuarios();

		// Table object (plansemanal)
		if (!isset($GLOBALS['plansemanal'])) $GLOBALS['plansemanal'] = new cplansemanal();

		// Page ID
		if (!defined("EW_PAGE_ID"))
			define("EW_PAGE_ID", 'add', TRUE);

		// Table name (for backward compatibility)
		if (!defined("EW_TABLE_NAME"))
			define("EW_TABLE_NAME", 'planoperaciones', TRUE);

		// Start timer
		if (!isset($GLOBALS["gTimer"])) $GLOBALS["gTimer"] = new cTimer();

		// Open connection
		if (!isset($conn)) $conn = ew_Connect();
	}

	// 
	//  Page_Init
	//
	function Page_Init() {
		global $gsExport, $gsExportFile, $UserProfile, $Language, $Security, $objForm;

		// Security
		$Security = new cAdvancedSecurity();
		if (!$Security->IsLoggedIn()) $Security->AutoLogin();
		if (!$Security->IsLoggedIn()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("login.php");
		}
		$Security->TablePermission_Loading();
		$Security->LoadCurrentUserLevel($this->ProjectID . $this->TableName);
		$Security->TablePermission_Loaded();
		if (!$Security->IsLoggedIn()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("login.php");
		}
		if (!$Security->CanAdd()) {
			$Security->SaveLastUrl();
			$this->setFailureMessage($Language->Phrase("NoPermission")); // Set no permission
			$this->Page_Terminate("planoperacioneslist.php");
		}

		// Create form object
		$objForm = new cFormObj();
		$this->CurrentAction = (@$_GET["a"] <> "") ? $_GET["a"] : @$_POST["a_list"]; // Set up curent action

		// Global Page Loading event (in userfn*.php)
		Page_Loading();

		// Page Load event
		$this->Page_Load();
	}

	//
	// Page_Terminate
	//
	function Page_Terminate($url = "") {
		global $conn;

		// Page Unload event
		$this->Page_Unload();

		// Global Page Unloaded event (in userfn*.php)
		Page_Unloaded();
		$this->Page_Redirecting($url);

		 // Close connection
		$conn->Close();

		// Go to URL if specified
		if ($url <> "") {
			if (!EW_DEBUG_ENABLED && ob_get_length())
				ob_end_clean();
			header("Location: " . $url);
		}
		exit();
	}
	var $DbMasterFilter = "";
	var $DbDetailFilter = "";
	var $Priv = 0;
	var $OldRecordset;
	var $CopyRecord;

	// 
	// Page main
	//
	function Page_Main() {
		global $objForm, $Language, $gsFormError;

		// Set up master/detail parameters
		$this->SetUpMasterParms();

		// Process form if post back
		if (@$_POST["a_add"] <> "") {
			$this->CurrentAction = $_POST["a_add"]; // Get form action
			$this->CopyRecord = $this->LoadOldRecord(); // Load old recordset
			$this->LoadFormValues(); // Load form values
		} else { // Not post back

			// Load key values from QueryString
			$this->CopyRecord = TRUE;
			if (@$_GET["Id"] != "") {
				$this->Id->setQueryStringValue($_GET["Id"]);
				$this->setKey("Id", $this->Id->CurrentValue); // Set up key
			} else {
				$this->setKey("Id", ""); // Clear key
				$this->CopyRecord = FALSE;
			}
			if ($this->CopyRecord) {
				$this->CurrentAction = "C"; // Copy record
			} else {
				$this->CurrentAction = "I"; // Display blank record
				$this->LoadDefaultValues(); // Load default values
			}
		}

		// Set up Breadcrumb
		$this->SetupBreadcrumb();

		// Set up detail parameters
		$this->SetUpDetailParms();

		// Validate form if post back
		if (@$_POST["a_add"] <> "") {
			if (!$this->ValidateForm()) {
				$this->CurrentAction = "I"; // Form error, reset action
				$this->EventCancelled = TRUE; // Event cancelled
				$this->RestoreFormValues(); // Restore form values
				$this->setFailureMessage($gsFormError);
			}
		}

		// Perform action based on action code
		switch ($this->CurrentAction) {
			case "I": // Blank record, no action required
				break;
			case "C": // Copy an existing record
				if (!$this->LoadRow()) { // Load record based on key
					if ($this->getFailureMessage() == "") $this->setFailureMessage($Language->Phrase("NoRecord")); // No record found
					$this->Page_Terminate("planoperacioneslist.php"); // No matching record, return to list
				}

				// Set up detail parameters
				$this->SetUpDetailParms();
				break;
			case "A": // Add new record
				$this->SendEmail = TRUE; // Send email on add success
				if ($this->AddRow($this->OldRecordset)) { // Add successful
					if ($this->getSuccessMessage() == "")
						$this->setSuccessMessage($Language->Phrase("AddSuccess")); // Set up success message
					if ($this->getCurrentDetailTable() <> "") // Master/detail add
						$sReturnUrl = $this->GetDetailUrl();
					else
						$sReturnUrl = $this->getReturnUrl();
					if (ew_GetPageName($sReturnUrl) == "planoperacionesview.php")
						$sReturnUrl = $this->GetViewUrl(); // View paging, return to view page with keyurl directly
					$this->Page_Terminate($sReturnUrl); // Clean up and return
				} else {
					$this->EventCancelled = TRUE; // Event cancelled
					$this->RestoreFormValues(); // Add failed, restore form values

					// Set up detail parameters
					$this->SetUpDetailParms();
				}
		}

		// Render row based on row type
		$this->RowType = EW_ROWTYPE_ADD;  // Render add type

		// Render row
		$this->ResetAttrs();
		$this->RenderRow();
	}

	// Get upload files
	function GetUploadFiles() {
		global $objForm;

		// Get upload data
	}

	// Load default values
	function LoadDefaultValues() {
		$this->Fecha->CurrentValue = NULL;
		$this->Fecha->OldValue = $this->Fecha->CurrentValue;
		$this->Plan->CurrentValue = NULL;
		$this->Plan->OldValue = $this->Plan->CurrentValue;
		$this->Descripcion->CurrentValue = NULL;
		$this->Descripcion->OldValue = $this->Descripcion->CurrentValue;
		$this->Origen->CurrentValue = 0;
		$this->Destino->CurrentValue = 0;
		$this->Chofer->CurrentValue = NULL;
		$this->Chofer->OldValue = $this->Chofer->CurrentValue;
		$this->Vehiculo->CurrentValue = NULL;
		$this->Vehiculo->OldValue = $this->Vehiculo->CurrentValue;
		$this->Pedido->CurrentValue = NULL;
		$this->Pedido->OldValue = $this->Pedido->CurrentValue;
		$this->Carga->CurrentValue = NULL;
		$this->Carga->OldValue = $this->Carga->CurrentValue;
		$this->Descarga->CurrentValue = NULL;
		$this->Descarga->OldValue = $this->Descarga->CurrentValue;
		$this->Retorno->CurrentValue = NULL;
		$this->Retorno->OldValue = $this->Retorno->CurrentValue;
		$this->Observacion->CurrentValue = NULL;
		$this->Observacion->OldValue = $this->Observacion->CurrentValue;
		$this->MostrarObservacion->CurrentValue = 0;
	}

	// Load form values
	function LoadFormValues() {

		// Load from form
		global $objForm;
		if (!$this->Fecha->FldIsDetailKey) {
			$this->Fecha->setFormValue($objForm->GetValue("x_Fecha"));
			$this->Fecha->CurrentValue = ew_UnFormatDateTime($this->Fecha->CurrentValue, 7);
		}
		if (!$this->Plan->FldIsDetailKey) {
			$this->Plan->setFormValue($objForm->GetValue("x_Plan"));
		}
		if (!$this->Descripcion->FldIsDetailKey) {
			$this->Descripcion->setFormValue($objForm->GetValue("x_Descripcion"));
		}
		if (!$this->Origen->FldIsDetailKey) {
			$this->Origen->setFormValue($objForm->GetValue("x_Origen"));
		}
		if (!$this->Destino->FldIsDetailKey) {
			$this->Destino->setFormValue($objForm->GetValue("x_Destino"));
		}
		if (!$this->Chofer->FldIsDetailKey) {
			$this->Chofer->setFormValue($objForm->GetValue("x_Chofer"));
		}
		if (!$this->Vehiculo->FldIsDetailKey) {
			$this->Vehiculo->setFormValue($objForm->GetValue("x_Vehiculo"));
		}
		if (!$this->Pedido->FldIsDetailKey) {
			$this->Pedido->setFormValue($objForm->GetValue("x_Pedido"));
			$this->Pedido->CurrentValue = ew_UnFormatDateTime($this->Pedido->CurrentValue, 11);
		}
		if (!$this->Carga->FldIsDetailKey) {
			$this->Carga->setFormValue($objForm->GetValue("x_Carga"));
			$this->Carga->CurrentValue = ew_UnFormatDateTime($this->Carga->CurrentValue, 11);
		}
		if (!$this->Descarga->FldIsDetailKey) {
			$this->Descarga->setFormValue($objForm->GetValue("x_Descarga"));
			$this->Descarga->CurrentValue = ew_UnFormatDateTime($this->Descarga->CurrentValue, 11);
		}
		if (!$this->Retorno->FldIsDetailKey) {
			$this->Retorno->setFormValue($objForm->GetValue("x_Retorno"));
			$this->Retorno->CurrentValue = ew_UnFormatDateTime($this->Retorno->CurrentValue, 11);
		}
		if (!$this->Observacion->FldIsDetailKey) {
			$this->Observacion->setFormValue($objForm->GetValue("x_Observacion"));
		}
		if (!$this->MostrarObservacion->FldIsDetailKey) {
			$this->MostrarObservacion->setFormValue($objForm->GetValue("x_MostrarObservacion"));
		}
	}

	// Restore form values
	function RestoreFormValues() {
		global $objForm;
		$this->LoadOldRecord();
		$this->Fecha->CurrentValue = $this->Fecha->FormValue;
		$this->Fecha->CurrentValue = ew_UnFormatDateTime($this->Fecha->CurrentValue, 7);
		$this->Plan->CurrentValue = $this->Plan->FormValue;
		$this->Descripcion->CurrentValue = $this->Descripcion->FormValue;
		$this->Origen->CurrentValue = $this->Origen->FormValue;
		$this->Destino->CurrentValue = $this->Destino->FormValue;
		$this->Chofer->CurrentValue = $this->Chofer->FormValue;
		$this->Vehiculo->CurrentValue = $this->Vehiculo->FormValue;
		$this->Pedido->CurrentValue = $this->Pedido->FormValue;
		$this->Pedido->CurrentValue = ew_UnFormatDateTime($this->Pedido->CurrentValue, 11);
		$this->Carga->CurrentValue = $this->Carga->FormValue;
		$this->Carga->CurrentValue = ew_UnFormatDateTime($this->Carga->CurrentValue, 11);
		$this->Descarga->CurrentValue = $this->Descarga->FormValue;
		$this->Descarga->CurrentValue = ew_UnFormatDateTime($this->Descarga->CurrentValue, 11);
		$this->Retorno->CurrentValue = $this->Retorno->FormValue;
		$this->Retorno->CurrentValue = ew_UnFormatDateTime($this->Retorno->CurrentValue, 11);
		$this->Observacion->CurrentValue = $this->Observacion->FormValue;
		$this->MostrarObservacion->CurrentValue = $this->MostrarObservacion->FormValue;
	}

	// Load row based on key values
	function LoadRow() {
		global $conn, $Security, $Language;
		$sFilter = $this->KeyFilter();

		// Call Row Selecting event
		$this->Row_Selecting($sFilter);

		// Load SQL based on filter
		$this->CurrentFilter = $sFilter;
		$sSql = $this->SQL();
		$res = FALSE;
		$rs = ew_LoadRecordset($sSql);
		if ($rs && !$rs->EOF) {
			$res = TRUE;
			$this->LoadRowValues($rs); // Load row values
			$rs->Close();
		}
		return $res;
	}

	// Load row values from recordset
	function LoadRowValues(&$rs) {
		global $conn;
		if (!$rs || $rs->EOF) return;

		// Call Row Selected event
		$row = &$rs->fields;
		$this->Row_Selected($row);
		$this->Id->setDbValue($rs->fields('Id'));
		$this->Fecha->setDbValue($rs->fields('Fecha'));
		$this->Plan->setDbValue($rs->fields('Plan'));
		$this->Estado->setDbValue($rs->fields('Estado'));
		$this->Descripcion->setDbValue($rs->fields('Descripcion'));
		$this->Origen->setDbValue($rs->fields('Origen'));
		$this->Destino->setDbValue($rs->fields('Destino'));
		$this->Chofer->setDbValue($rs->fields('Chofer'));
		$this->Vehiculo->setDbValue($rs->fields('Vehiculo'));
		$this->Pedido->setDbValue($rs->fields('Pedido'));
		$this->Carga->setDbValue($rs->fields('Carga'));
		$this->Descarga->setDbValue($rs->fields('Descarga'));
		$this->Retorno->setDbValue($rs->fields('Retorno'));
		$this->Observacion->setDbValue($rs->fields('Observacion'));
		$this->MostrarObservacion->setDbValue($rs->fields('MostrarObservacion'));
		$this->FechaActualizacion->setDbValue($rs->fields('FechaActualizacion'));
	}

	// Load DbValue from recordset
	function LoadDbValues(&$rs) {
		if (!$rs || !is_array($rs) && $rs->EOF) return;
		$row = is_array($rs) ? $rs : $rs->fields;
		$this->Id->DbValue = $row['Id'];
		$this->Fecha->DbValue = $row['Fecha'];
		$this->Plan->DbValue = $row['Plan'];
		$this->Estado->DbValue = $row['Estado'];
		$this->Descripcion->DbValue = $row['Descripcion'];
		$this->Origen->DbValue = $row['Origen'];
		$this->Destino->DbValue = $row['Destino'];
		$this->Chofer->DbValue = $row['Chofer'];
		$this->Vehiculo->DbValue = $row['Vehiculo'];
		$this->Pedido->DbValue = $row['Pedido'];
		$this->Carga->DbValue = $row['Carga'];
		$this->Descarga->DbValue = $row['Descarga'];
		$this->Retorno->DbValue = $row['Retorno'];
		$this->Observacion->DbValue = $row['Observacion'];
		$this->MostrarObservacion->DbValue = $row['MostrarObservacion'];
		$this->FechaActualizacion->DbValue = $row['FechaActualizacion'];
	}

	// Load old record
	function LoadOldRecord() {

		// Load key values from Session
		$bValidKey = TRUE;
		if (strval($this->getKey("Id")) <> "")
			$this->Id->CurrentValue = $this->getKey("Id"); // Id
		else
			$bValidKey = FALSE;

		// Load old recordset
		if ($bValidKey) {
			$this->CurrentFilter = $this->KeyFilter();
			$sSql = $this->SQL();
			$this->OldRecordset = ew_LoadRecordset($sSql);
			$this->LoadRowValues($this->OldRecordset); // Load row values
		} else {
			$this->OldRecordset = NULL;
		}
		return $bValidKey;
	}

	// Render row values based on field settings
	function RenderRow() {
		global $conn, $Security, $Language;
		global $gsLanguage;

		// Initialize URLs
		// Call Row_Rendering event

		$this->Row_Rendering();

		// Common render codes for all row types
		// Id
		// Fecha
		// Plan
		// Estado
		// Descripcion
		// Origen
		// Destino
		// Chofer
		// Vehiculo
		// Pedido
		// Carga
		// Descarga
		// Retorno
		// Observacion
		// MostrarObservacion
		// FechaActualizacion

		if ($this->RowType == EW_ROWTYPE_VIEW) { // View row

			// Id
			$this->Id->ViewValue = $this->Id->CurrentValue;
			$this->Id->ViewCustomAttributes = "";

			// Fecha
			$this->Fecha->ViewValue = $this->Fecha->CurrentValue;
			$this->Fecha->ViewValue = ew_FormatDateTime($this->Fecha->ViewValue, 7);
			$this->Fecha->ViewCustomAttributes = "";

			// Plan
			$this->Plan->ViewValue = $this->Plan->CurrentValue;
			if (strval($this->Plan->CurrentValue) <> "") {
				$sFilterWrk = "`PlanId`" . ew_SearchString("=", $this->Plan->CurrentValue, EW_DATATYPE_NUMBER);
			$sSqlWrk = "SELECT `PlanId`, `PlanDescripcion` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `plansemanal`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->Plan, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$this->Plan->ViewValue = $rswrk->fields('DispFld');
					$rswrk->Close();
				} else {
					$this->Plan->ViewValue = $this->Plan->CurrentValue;
				}
			} else {
				$this->Plan->ViewValue = NULL;
			}
			$this->Plan->ViewValue = ew_FormatDateTime($this->Plan->ViewValue, 7);
			$this->Plan->ViewCustomAttributes = "";

			// Estado
			if (strval($this->Estado->CurrentValue) <> "") {
				switch ($this->Estado->CurrentValue) {
					case $this->Estado->FldTagValue(1):
						$this->Estado->ViewValue = $this->Estado->FldTagCaption(1) <> "" ? $this->Estado->FldTagCaption(1) : $this->Estado->CurrentValue;
						break;
					case $this->Estado->FldTagValue(2):
						$this->Estado->ViewValue = $this->Estado->FldTagCaption(2) <> "" ? $this->Estado->FldTagCaption(2) : $this->Estado->CurrentValue;
						break;
					case $this->Estado->FldTagValue(3):
						$this->Estado->ViewValue = $this->Estado->FldTagCaption(3) <> "" ? $this->Estado->FldTagCaption(3) : $this->Estado->CurrentValue;
						break;
					default:
						$this->Estado->ViewValue = $this->Estado->CurrentValue;
				}
			} else {
				$this->Estado->ViewValue = NULL;
			}
			$this->Estado->ViewCustomAttributes = "";

			// Descripcion
			$this->Descripcion->ViewValue = $this->Descripcion->CurrentValue;
			$this->Descripcion->ViewCustomAttributes = "";

			// Origen
			if (strval($this->Origen->CurrentValue) <> "") {
				switch ($this->Origen->CurrentValue) {
					case $this->Origen->FldTagValue(1):
						$this->Origen->ViewValue = $this->Origen->FldTagCaption(1) <> "" ? $this->Origen->FldTagCaption(1) : $this->Origen->CurrentValue;
						break;
					case $this->Origen->FldTagValue(2):
						$this->Origen->ViewValue = $this->Origen->FldTagCaption(2) <> "" ? $this->Origen->FldTagCaption(2) : $this->Origen->CurrentValue;
						break;
					case $this->Origen->FldTagValue(3):
						$this->Origen->ViewValue = $this->Origen->FldTagCaption(3) <> "" ? $this->Origen->FldTagCaption(3) : $this->Origen->CurrentValue;
						break;
					default:
						$this->Origen->ViewValue = $this->Origen->CurrentValue;
				}
			} else {
				$this->Origen->ViewValue = NULL;
			}
			$this->Origen->ViewCustomAttributes = "";

			// Destino
			if (strval($this->Destino->CurrentValue) <> "") {
				$sFilterWrk = "`sucursalId`" . ew_SearchString("=", $this->Destino->CurrentValue, EW_DATATYPE_NUMBER);
			$sSqlWrk = "SELECT `sucursalId`, `sucursalNombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `sucursales`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->Destino, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$this->Destino->ViewValue = $rswrk->fields('DispFld');
					$rswrk->Close();
				} else {
					$this->Destino->ViewValue = $this->Destino->CurrentValue;
				}
			} else {
				$this->Destino->ViewValue = NULL;
			}
			$this->Destino->ViewCustomAttributes = "";

			// Chofer
			if (strval($this->Chofer->CurrentValue) <> "") {
				$sFilterWrk = "`ChoId`" . ew_SearchString("=", $this->Chofer->CurrentValue, EW_DATATYPE_NUMBER);
			$sSqlWrk = "SELECT `ChoId`, `ChoNombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `choferes`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->Chofer, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$this->Chofer->ViewValue = $rswrk->fields('DispFld');
					$rswrk->Close();
				} else {
					$this->Chofer->ViewValue = $this->Chofer->CurrentValue;
				}
			} else {
				$this->Chofer->ViewValue = NULL;
			}
			$this->Chofer->ViewCustomAttributes = "";

			// Vehiculo
			if (strval($this->Vehiculo->CurrentValue) <> "") {
				$sFilterWrk = "`VehId`" . ew_SearchString("=", $this->Vehiculo->CurrentValue, EW_DATATYPE_NUMBER);
			$sSqlWrk = "SELECT `VehId`, `VehPatente` AS `DispFld`, `VehDescripcion` AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `vehiculos`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->Vehiculo, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$this->Vehiculo->ViewValue = $rswrk->fields('DispFld');
					$this->Vehiculo->ViewValue .= ew_ValueSeparator(1,$this->Vehiculo) . $rswrk->fields('Disp2Fld');
					$rswrk->Close();
				} else {
					$this->Vehiculo->ViewValue = $this->Vehiculo->CurrentValue;
				}
			} else {
				$this->Vehiculo->ViewValue = NULL;
			}
			$this->Vehiculo->ViewCustomAttributes = "";

			// Pedido
			$this->Pedido->ViewValue = $this->Pedido->CurrentValue;
			$this->Pedido->ViewValue = ew_FormatDateTime($this->Pedido->ViewValue, 11);
			$this->Pedido->ViewCustomAttributes = "";

			// Carga
			$this->Carga->ViewValue = $this->Carga->CurrentValue;
			$this->Carga->ViewValue = ew_FormatDateTime($this->Carga->ViewValue, 11);
			$this->Carga->ViewCustomAttributes = "";

			// Descarga
			$this->Descarga->ViewValue = $this->Descarga->CurrentValue;
			$this->Descarga->ViewValue = ew_FormatDateTime($this->Descarga->ViewValue, 11);
			$this->Descarga->ViewCustomAttributes = "";

			// Retorno
			$this->Retorno->ViewValue = $this->Retorno->CurrentValue;
			$this->Retorno->ViewValue = ew_FormatDateTime($this->Retorno->ViewValue, 11);
			$this->Retorno->ViewCustomAttributes = "";

			// Observacion
			$this->Observacion->ViewValue = $this->Observacion->CurrentValue;
			$this->Observacion->ViewCustomAttributes = "";

			// MostrarObservacion
			if (strval($this->MostrarObservacion->CurrentValue) <> "") {
				$this->MostrarObservacion->ViewValue = "";
				$arwrk = explode(",", strval($this->MostrarObservacion->CurrentValue));
				$cnt = count($arwrk);
				for ($ari = 0; $ari < $cnt; $ari++) {
					switch (trim($arwrk[$ari])) {
						case $this->MostrarObservacion->FldTagValue(1):
							$this->MostrarObservacion->ViewValue .= $this->MostrarObservacion->FldTagCaption(1) <> "" ? $this->MostrarObservacion->FldTagCaption(1) : trim($arwrk[$ari]);
							break;
						default:
							$this->MostrarObservacion->ViewValue .= trim($arwrk[$ari]);
					}
					if ($ari < $cnt-1) $this->MostrarObservacion->ViewValue .= ew_ViewOptionSeparator($ari);
				}
			} else {
				$this->MostrarObservacion->ViewValue = NULL;
			}
			$this->MostrarObservacion->ViewCustomAttributes = "";

			// FechaActualizacion
			$this->FechaActualizacion->ViewValue = $this->FechaActualizacion->CurrentValue;
			$this->FechaActualizacion->ViewValue = ew_FormatDateTime($this->FechaActualizacion->ViewValue, 11);
			$this->FechaActualizacion->ViewCustomAttributes = "";

			// Fecha
			$this->Fecha->LinkCustomAttributes = "";
			$this->Fecha->HrefValue = "";
			$this->Fecha->TooltipValue = "";

			// Plan
			$this->Plan->LinkCustomAttributes = "";
			$this->Plan->HrefValue = "";
			$this->Plan->TooltipValue = "";

			// Descripcion
			$this->Descripcion->LinkCustomAttributes = "";
			$this->Descripcion->HrefValue = "";
			$this->Descripcion->TooltipValue = "";

			// Origen
			$this->Origen->LinkCustomAttributes = "";
			$this->Origen->HrefValue = "";
			$this->Origen->TooltipValue = "";

			// Destino
			$this->Destino->LinkCustomAttributes = "";
			$this->Destino->HrefValue = "";
			$this->Destino->TooltipValue = "";

			// Chofer
			$this->Chofer->LinkCustomAttributes = "";
			$this->Chofer->HrefValue = "";
			$this->Chofer->TooltipValue = "";

			// Vehiculo
			$this->Vehiculo->LinkCustomAttributes = "";
			$this->Vehiculo->HrefValue = "";
			$this->Vehiculo->TooltipValue = "";

			// Pedido
			$this->Pedido->LinkCustomAttributes = "";
			$this->Pedido->HrefValue = "";
			$this->Pedido->TooltipValue = "";

			// Carga
			$this->Carga->LinkCustomAttributes = "";
			$this->Carga->HrefValue = "";
			$this->Carga->TooltipValue = "";

			// Descarga
			$this->Descarga->LinkCustomAttributes = "";
			$this->Descarga->HrefValue = "";
			$this->Descarga->TooltipValue = "";

			// Retorno
			$this->Retorno->LinkCustomAttributes = "";
			$this->Retorno->HrefValue = "";
			$this->Retorno->TooltipValue = "";

			// Observacion
			$this->Observacion->LinkCustomAttributes = "";
			$this->Observacion->HrefValue = "";
			$this->Observacion->TooltipValue = "";

			// MostrarObservacion
			$this->MostrarObservacion->LinkCustomAttributes = "";
			$this->MostrarObservacion->HrefValue = "";
			$this->MostrarObservacion->TooltipValue = "";
		} elseif ($this->RowType == EW_ROWTYPE_ADD) { // Add row

			// Fecha
			$this->Fecha->EditCustomAttributes = "";
			$this->Fecha->EditValue = ew_HtmlEncode(ew_FormatDateTime($this->Fecha->CurrentValue, 7));
			$this->Fecha->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->Fecha->FldCaption()));

			// Plan
			$this->Plan->EditCustomAttributes = "";
			if ($this->Plan->getSessionValue() <> "") {
				$this->Plan->CurrentValue = $this->Plan->getSessionValue();
			$this->Plan->ViewValue = $this->Plan->CurrentValue;
			if (strval($this->Plan->CurrentValue) <> "") {
				$sFilterWrk = "`PlanId`" . ew_SearchString("=", $this->Plan->CurrentValue, EW_DATATYPE_NUMBER);
			$sSqlWrk = "SELECT `PlanId`, `PlanDescripcion` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `plansemanal`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->Plan, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$this->Plan->ViewValue = $rswrk->fields('DispFld');
					$rswrk->Close();
				} else {
					$this->Plan->ViewValue = $this->Plan->CurrentValue;
				}
			} else {
				$this->Plan->ViewValue = NULL;
			}
			$this->Plan->ViewValue = ew_FormatDateTime($this->Plan->ViewValue, 7);
			$this->Plan->ViewCustomAttributes = "";
			} else {
			$this->Plan->EditValue = ew_HtmlEncode($this->Plan->CurrentValue);
			if (strval($this->Plan->CurrentValue) <> "") {
				$sFilterWrk = "`PlanId`" . ew_SearchString("=", $this->Plan->CurrentValue, EW_DATATYPE_NUMBER);
			$sSqlWrk = "SELECT `PlanId`, `PlanDescripcion` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `plansemanal`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->Plan, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$this->Plan->EditValue = ew_HtmlEncode($rswrk->fields('DispFld'));
					$rswrk->Close();
				} else {
					$this->Plan->EditValue = ew_HtmlEncode($this->Plan->CurrentValue);
				}
			} else {
				$this->Plan->EditValue = NULL;
			}
			$this->Plan->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->Plan->FldCaption()));
			}

			// Descripcion
			$this->Descripcion->EditCustomAttributes = "";
			$this->Descripcion->EditValue = ew_HtmlEncode($this->Descripcion->CurrentValue);
			$this->Descripcion->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->Descripcion->FldCaption()));

			// Origen
			$this->Origen->EditCustomAttributes = "";
			$arwrk = array();
			$arwrk[] = array($this->Origen->FldTagValue(1), $this->Origen->FldTagCaption(1) <> "" ? $this->Origen->FldTagCaption(1) : $this->Origen->FldTagValue(1));
			$arwrk[] = array($this->Origen->FldTagValue(2), $this->Origen->FldTagCaption(2) <> "" ? $this->Origen->FldTagCaption(2) : $this->Origen->FldTagValue(2));
			$arwrk[] = array($this->Origen->FldTagValue(3), $this->Origen->FldTagCaption(3) <> "" ? $this->Origen->FldTagCaption(3) : $this->Origen->FldTagValue(3));
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$this->Origen->EditValue = $arwrk;

			// Destino
			$this->Destino->EditCustomAttributes = "";
			$sFilterWrk = "";
			$sSqlWrk = "SELECT `sucursalId`, `sucursalNombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld`, '' AS `SelectFilterFld`, '' AS `SelectFilterFld2`, '' AS `SelectFilterFld3`, '' AS `SelectFilterFld4` FROM `sucursales`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->Destino, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect"), "", "", "", "", "", "", ""));
			$this->Destino->EditValue = $arwrk;

			// Chofer
			$this->Chofer->EditCustomAttributes = "";
			if (trim(strval($this->Chofer->CurrentValue)) == "") {
				$sFilterWrk = "0=1";
			} else {
				$sFilterWrk = "`ChoId`" . ew_SearchString("=", $this->Chofer->CurrentValue, EW_DATATYPE_NUMBER);
			}
			$sSqlWrk = "SELECT `ChoId`, `ChoNombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld`, '' AS `SelectFilterFld`, '' AS `SelectFilterFld2`, '' AS `SelectFilterFld3`, '' AS `SelectFilterFld4` FROM `choferes`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->Chofer, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect"), "", "", "", "", "", "", ""));
			$this->Chofer->EditValue = $arwrk;

			// Vehiculo
			$this->Vehiculo->EditCustomAttributes = "";
			if (trim(strval($this->Vehiculo->CurrentValue)) == "") {
				$sFilterWrk = "0=1";
			} else {
				$sFilterWrk = "`VehId`" . ew_SearchString("=", $this->Vehiculo->CurrentValue, EW_DATATYPE_NUMBER);
			}
			$sSqlWrk = "SELECT `VehId`, `VehPatente` AS `DispFld`, `VehDescripcion` AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld`, '' AS `SelectFilterFld`, '' AS `SelectFilterFld2`, '' AS `SelectFilterFld3`, '' AS `SelectFilterFld4` FROM `vehiculos`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->Vehiculo, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect"), "", "", "", "", "", "", ""));
			$this->Vehiculo->EditValue = $arwrk;

			// Pedido
			$this->Pedido->EditCustomAttributes = "";
			$this->Pedido->EditValue = ew_HtmlEncode(ew_FormatDateTime($this->Pedido->CurrentValue, 11));
			$this->Pedido->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->Pedido->FldCaption()));

			// Carga
			$this->Carga->EditCustomAttributes = "";
			$this->Carga->EditValue = ew_HtmlEncode(ew_FormatDateTime($this->Carga->CurrentValue, 11));
			$this->Carga->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->Carga->FldCaption()));

			// Descarga
			$this->Descarga->EditCustomAttributes = "";
			$this->Descarga->EditValue = ew_HtmlEncode(ew_FormatDateTime($this->Descarga->CurrentValue, 11));
			$this->Descarga->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->Descarga->FldCaption()));

			// Retorno
			$this->Retorno->EditCustomAttributes = "";
			$this->Retorno->EditValue = ew_HtmlEncode(ew_FormatDateTime($this->Retorno->CurrentValue, 11));
			$this->Retorno->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->Retorno->FldCaption()));

			// Observacion
			$this->Observacion->EditCustomAttributes = "";
			$this->Observacion->EditValue = ew_HtmlEncode($this->Observacion->CurrentValue);
			$this->Observacion->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->Observacion->FldCaption()));

			// MostrarObservacion
			$this->MostrarObservacion->EditCustomAttributes = "";
			$arwrk = array();
			$arwrk[] = array($this->MostrarObservacion->FldTagValue(1), $this->MostrarObservacion->FldTagCaption(1) <> "" ? $this->MostrarObservacion->FldTagCaption(1) : $this->MostrarObservacion->FldTagValue(1));
			$this->MostrarObservacion->EditValue = $arwrk;

			// Edit refer script
			// Fecha

			$this->Fecha->HrefValue = "";

			// Plan
			$this->Plan->HrefValue = "";

			// Descripcion
			$this->Descripcion->HrefValue = "";

			// Origen
			$this->Origen->HrefValue = "";

			// Destino
			$this->Destino->HrefValue = "";

			// Chofer
			$this->Chofer->HrefValue = "";

			// Vehiculo
			$this->Vehiculo->HrefValue = "";

			// Pedido
			$this->Pedido->HrefValue = "";

			// Carga
			$this->Carga->HrefValue = "";

			// Descarga
			$this->Descarga->HrefValue = "";

			// Retorno
			$this->Retorno->HrefValue = "";

			// Observacion
			$this->Observacion->HrefValue = "";

			// MostrarObservacion
			$this->MostrarObservacion->HrefValue = "";
		}
		if ($this->RowType == EW_ROWTYPE_ADD ||
			$this->RowType == EW_ROWTYPE_EDIT ||
			$this->RowType == EW_ROWTYPE_SEARCH) { // Add / Edit / Search row
			$this->SetupFieldTitles();
		}

		// Call Row Rendered event
		if ($this->RowType <> EW_ROWTYPE_AGGREGATEINIT)
			$this->Row_Rendered();
	}

	// Validate form
	function ValidateForm() {
		global $Language, $gsFormError;

		// Initialize form error message
		$gsFormError = "";

		// Check if validation required
		if (!EW_SERVER_VALIDATE)
			return ($gsFormError == "");
		if (!ew_CheckEuroDate($this->Fecha->FormValue)) {
			ew_AddMessage($gsFormError, $this->Fecha->FldErrMsg());
		}
		if (!ew_CheckInteger($this->Plan->FormValue)) {
			ew_AddMessage($gsFormError, $this->Plan->FldErrMsg());
		}
		if (!$this->Origen->FldIsDetailKey && !is_null($this->Origen->FormValue) && $this->Origen->FormValue == "") {
			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $this->Origen->FldCaption());
		}
		if (!$this->Destino->FldIsDetailKey && !is_null($this->Destino->FormValue) && $this->Destino->FormValue == "") {
			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $this->Destino->FldCaption());
		}
		if (!ew_CheckEuroDate($this->Pedido->FormValue)) {
			ew_AddMessage($gsFormError, $this->Pedido->FldErrMsg());
		}
		if (!ew_CheckEuroDate($this->Carga->FormValue)) {
			ew_AddMessage($gsFormError, $this->Carga->FldErrMsg());
		}
		if (!ew_CheckEuroDate($this->Descarga->FormValue)) {
			ew_AddMessage($gsFormError, $this->Descarga->FldErrMsg());
		}
		if (!ew_CheckEuroDate($this->Retorno->FormValue)) {
			ew_AddMessage($gsFormError, $this->Retorno->FldErrMsg());
		}

		// Validate detail grid
		$DetailTblVar = explode(",", $this->getCurrentDetailTable());
		if (in_array("pedidoplan", $DetailTblVar) && $GLOBALS["pedidoplan"]->DetailAdd) {
			if (!isset($GLOBALS["pedidoplan_grid"])) $GLOBALS["pedidoplan_grid"] = new cpedidoplan_grid(); // get detail page object
			$GLOBALS["pedidoplan_grid"]->ValidateGridForm();
		}

		// Return validate result
		$ValidateForm = ($gsFormError == "");

		// Call Form_CustomValidate event
		$sFormCustomError = "";
		$ValidateForm = $ValidateForm && $this->Form_CustomValidate($sFormCustomError);
		if ($sFormCustomError <> "") {
			ew_AddMessage($gsFormError, $sFormCustomError);
		}
		return $ValidateForm;
	}

	// Add record
	function AddRow($rsold = NULL) {
		global $conn, $Language, $Security;

		// Check referential integrity for master table 'plansemanal'
		$bValidMasterRecord = TRUE;
		$sMasterFilter = $this->SqlMasterFilter_plansemanal();
		if (strval($this->Plan->CurrentValue) <> "") {
			$sMasterFilter = str_replace("@PlanId@", ew_AdjustSql($this->Plan->CurrentValue), $sMasterFilter);
		} else {
			$bValidMasterRecord = FALSE;
		}
		if ($bValidMasterRecord) {
			$rsmaster = $GLOBALS["plansemanal"]->LoadRs($sMasterFilter);
			$bValidMasterRecord = ($rsmaster && !$rsmaster->EOF);
			$rsmaster->Close();
		}
		if (!$bValidMasterRecord) {
			$sRelatedRecordMsg = str_replace("%t", "plansemanal", $Language->Phrase("RelatedRecordRequired"));
			$this->setFailureMessage($sRelatedRecordMsg);
			return FALSE;
		}

		// Begin transaction
		if ($this->getCurrentDetailTable() <> "")
			$conn->BeginTrans();

		// Load db values from rsold
		if ($rsold) {
			$this->LoadDbValues($rsold);
		}
		$rsnew = array();

		// Fecha
		$this->Fecha->SetDbValueDef($rsnew, ew_UnFormatDateTime($this->Fecha->CurrentValue, 7), NULL, FALSE);

		// Plan
		$this->Plan->SetDbValueDef($rsnew, $this->Plan->CurrentValue, NULL, FALSE);

		// Descripcion
		$this->Descripcion->SetDbValueDef($rsnew, $this->Descripcion->CurrentValue, NULL, FALSE);

		// Origen
		$this->Origen->SetDbValueDef($rsnew, $this->Origen->CurrentValue, 0, strval($this->Origen->CurrentValue) == "");

		// Destino
		$this->Destino->SetDbValueDef($rsnew, $this->Destino->CurrentValue, 0, strval($this->Destino->CurrentValue) == "");

		// Chofer
		$this->Chofer->SetDbValueDef($rsnew, $this->Chofer->CurrentValue, NULL, FALSE);

		// Vehiculo
		$this->Vehiculo->SetDbValueDef($rsnew, $this->Vehiculo->CurrentValue, NULL, FALSE);

		// Pedido
		$this->Pedido->SetDbValueDef($rsnew, ew_UnFormatDateTime($this->Pedido->CurrentValue, 11), NULL, FALSE);

		// Carga
		$this->Carga->SetDbValueDef($rsnew, ew_UnFormatDateTime($this->Carga->CurrentValue, 11), NULL, FALSE);

		// Descarga
		$this->Descarga->SetDbValueDef($rsnew, ew_UnFormatDateTime($this->Descarga->CurrentValue, 11), NULL, FALSE);

		// Retorno
		$this->Retorno->SetDbValueDef($rsnew, ew_UnFormatDateTime($this->Retorno->CurrentValue, 11), NULL, FALSE);

		// Observacion
		$this->Observacion->SetDbValueDef($rsnew, $this->Observacion->CurrentValue, NULL, FALSE);

		// MostrarObservacion
		$this->MostrarObservacion->SetDbValueDef($rsnew, $this->MostrarObservacion->CurrentValue, NULL, strval($this->MostrarObservacion->CurrentValue) == "");

		// Call Row Inserting event
		$rs = ($rsold == NULL) ? NULL : $rsold->fields;
		$bInsertRow = $this->Row_Inserting($rs, $rsnew);
		if ($bInsertRow) {
			$conn->raiseErrorFn = 'ew_ErrorFn';
			$AddRow = $this->Insert($rsnew);
			$conn->raiseErrorFn = '';
			if ($AddRow) {
			}
		} else {
			if ($this->getSuccessMessage() <> "" || $this->getFailureMessage() <> "") {

				// Use the message, do nothing
			} elseif ($this->CancelMessage <> "") {
				$this->setFailureMessage($this->CancelMessage);
				$this->CancelMessage = "";
			} else {
				$this->setFailureMessage($Language->Phrase("InsertCancelled"));
			}
			$AddRow = FALSE;
		}

		// Get insert id if necessary
		if ($AddRow) {
			$this->Id->setDbValue($conn->Insert_ID());
			$rsnew['Id'] = $this->Id->DbValue;
		}

		// Add detail records
		if ($AddRow) {
			$DetailTblVar = explode(",", $this->getCurrentDetailTable());
			if (in_array("pedidoplan", $DetailTblVar) && $GLOBALS["pedidoplan"]->DetailAdd) {
				$GLOBALS["pedidoplan"]->Plan->setSessionValue($this->Id->CurrentValue); // Set master key
				if (!isset($GLOBALS["pedidoplan_grid"])) $GLOBALS["pedidoplan_grid"] = new cpedidoplan_grid(); // Get detail page object
				$AddRow = $GLOBALS["pedidoplan_grid"]->GridInsert();
				if (!$AddRow)
					$GLOBALS["pedidoplan"]->Plan->setSessionValue(""); // Clear master key if insert failed
			}
		}

		// Commit/Rollback transaction
		if ($this->getCurrentDetailTable() <> "") {
			if ($AddRow) {
				$conn->CommitTrans(); // Commit transaction
			} else {
				$conn->RollbackTrans(); // Rollback transaction
			}
		}
		if ($AddRow) {

			// Call Row Inserted event
			$rs = ($rsold == NULL) ? NULL : $rsold->fields;
			$this->Row_Inserted($rs, $rsnew);
		}
		return $AddRow;
	}

	// Set up master/detail based on QueryString
	function SetUpMasterParms() {
		$bValidMaster = FALSE;

		// Get the keys for master table
		if (isset($_GET[EW_TABLE_SHOW_MASTER])) {
			$sMasterTblVar = $_GET[EW_TABLE_SHOW_MASTER];
			if ($sMasterTblVar == "") {
				$bValidMaster = TRUE;
				$this->DbMasterFilter = "";
				$this->DbDetailFilter = "";
			}
			if ($sMasterTblVar == "plansemanal") {
				$bValidMaster = TRUE;
				if (@$_GET["PlanId"] <> "") {
					$GLOBALS["plansemanal"]->PlanId->setQueryStringValue($_GET["PlanId"]);
					$this->Plan->setQueryStringValue($GLOBALS["plansemanal"]->PlanId->QueryStringValue);
					$this->Plan->setSessionValue($this->Plan->QueryStringValue);
					if (!is_numeric($GLOBALS["plansemanal"]->PlanId->QueryStringValue)) $bValidMaster = FALSE;
				} else {
					$bValidMaster = FALSE;
				}
			}
		}
		if ($bValidMaster) {

			// Save current master table
			$this->setCurrentMasterTable($sMasterTblVar);

			// Reset start record counter (new master key)
			$this->StartRec = 1;
			$this->setStartRecordNumber($this->StartRec);

			// Clear previous master key from Session
			if ($sMasterTblVar <> "plansemanal") {
				if ($this->Plan->QueryStringValue == "") $this->Plan->setSessionValue("");
			}
		}
		$this->DbMasterFilter = $this->GetMasterFilter(); //  Get master filter
		$this->DbDetailFilter = $this->GetDetailFilter(); // Get detail filter
	}

	// Set up detail parms based on QueryString
	function SetUpDetailParms() {

		// Get the keys for master table
		if (isset($_GET[EW_TABLE_SHOW_DETAIL])) {
			$sDetailTblVar = $_GET[EW_TABLE_SHOW_DETAIL];
			$this->setCurrentDetailTable($sDetailTblVar);
		} else {
			$sDetailTblVar = $this->getCurrentDetailTable();
		}
		if ($sDetailTblVar <> "") {
			$DetailTblVar = explode(",", $sDetailTblVar);
			if (in_array("pedidoplan", $DetailTblVar)) {
				if (!isset($GLOBALS["pedidoplan_grid"]))
					$GLOBALS["pedidoplan_grid"] = new cpedidoplan_grid;
				if ($GLOBALS["pedidoplan_grid"]->DetailAdd) {
					if ($this->CopyRecord)
						$GLOBALS["pedidoplan_grid"]->CurrentMode = "copy";
					else
						$GLOBALS["pedidoplan_grid"]->CurrentMode = "add";
					$GLOBALS["pedidoplan_grid"]->CurrentAction = "gridadd";

					// Save current master table to detail table
					$GLOBALS["pedidoplan_grid"]->setCurrentMasterTable($this->TableVar);
					$GLOBALS["pedidoplan_grid"]->setStartRecordNumber(1);
					$GLOBALS["pedidoplan_grid"]->Plan->FldIsDetailKey = TRUE;
					$GLOBALS["pedidoplan_grid"]->Plan->CurrentValue = $this->Id->CurrentValue;
					$GLOBALS["pedidoplan_grid"]->Plan->setSessionValue($GLOBALS["pedidoplan_grid"]->Plan->CurrentValue);
				}
			}
		}
	}

	// Set up Breadcrumb
	function SetupBreadcrumb() {
		global $Breadcrumb, $Language;
		$Breadcrumb = new cBreadcrumb();
		$Breadcrumb->Add("list", $this->TableVar, "planoperacioneslist.php", $this->TableVar, TRUE);
		$PageId = ($this->CurrentAction == "C") ? "Copy" : "Add";
		$Breadcrumb->Add("add", $PageId, ew_CurrentUrl());
	}

	// Page Load event
	function Page_Load() {

		//echo "Page Load";
	}

	// Page Unload event
	function Page_Unload() {

		//echo "Page Unload";
	}

	// Page Redirecting event
	function Page_Redirecting(&$url) {

		// Example:
		//$url = "your URL";

	}

	// Message Showing event
	// $type = ''|'success'|'failure'|'warning'
	function Message_Showing(&$msg, $type) {
		if ($type == 'success') {

			//$msg = "your success message";
		} elseif ($type == 'failure') {

			//$msg = "your failure message";
		} elseif ($type == 'warning') {

			//$msg = "your warning message";
		} else {

			//$msg = "your message";
		}
	}

	// Page Render event
	function Page_Render() {

		//echo "Page Render";
	}

	// Page Data Rendering event
	function Page_DataRendering(&$header) {

		// Example:
		//$header = "your header";

	}

	// Page Data Rendered event
	function Page_DataRendered(&$footer) {

		// Example:
		//$footer = "your footer";

	}

	// Form Custom Validate event
	function Form_CustomValidate(&$CustomError) {

		// Return error message in CustomError
		return TRUE;
	}
}
?>
<?php ew_Header(FALSE) ?>
<?php

// Create page object
if (!isset($planoperaciones_add)) $planoperaciones_add = new cplanoperaciones_add();

// Page init
$planoperaciones_add->Page_Init();

// Page main
$planoperaciones_add->Page_Main();

// Global Page Rendering event (in userfn*.php)
Page_Rendering();

// Page Rendering event
$planoperaciones_add->Page_Render();
?>
<?php include_once "header.php" ?>
<script type="text/javascript">

// Page object
var planoperaciones_add = new ew_Page("planoperaciones_add");
planoperaciones_add.PageID = "add"; // Page ID
var EW_PAGE_ID = planoperaciones_add.PageID; // For backward compatibility

// Form object
var fplanoperacionesadd = new ew_Form("fplanoperacionesadd");

// Validate form
fplanoperacionesadd.Validate = function() {
	if (!this.ValidateRequired)
		return true; // Ignore validation
	var $ = jQuery, fobj = this.GetForm(), $fobj = $(fobj);
	this.PostAutoSuggest();
	if ($fobj.find("#a_confirm").val() == "F")
		return true;
	var elm, felm, uelm, addcnt = 0;
	var $k = $fobj.find("#" + this.FormKeyCountName); // Get key_count
	var rowcnt = ($k[0]) ? parseInt($k.val(), 10) : 1;
	var startcnt = (rowcnt == 0) ? 0 : 1; // Check rowcnt == 0 => Inline-Add
	var gridinsert = $fobj.find("#a_list").val() == "gridinsert";
	for (var i = startcnt; i <= rowcnt; i++) {
		var infix = ($k[0]) ? String(i) : "";
		$fobj.data("rowindex", infix);
			elm = this.GetElements("x" + infix + "_Fecha");
			if (elm && !ew_CheckEuroDate(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($planoperaciones->Fecha->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_Plan");
			if (elm && !ew_CheckInteger(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($planoperaciones->Plan->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_Origen");
			if (elm && !ew_HasValue(elm))
				return this.OnError(elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($planoperaciones->Origen->FldCaption()) ?>");
			elm = this.GetElements("x" + infix + "_Destino");
			if (elm && !ew_HasValue(elm))
				return this.OnError(elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($planoperaciones->Destino->FldCaption()) ?>");
			elm = this.GetElements("x" + infix + "_Pedido");
			if (elm && !ew_CheckEuroDate(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($planoperaciones->Pedido->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_Carga");
			if (elm && !ew_CheckEuroDate(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($planoperaciones->Carga->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_Descarga");
			if (elm && !ew_CheckEuroDate(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($planoperaciones->Descarga->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_Retorno");
			if (elm && !ew_CheckEuroDate(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($planoperaciones->Retorno->FldErrMsg()) ?>");

			// Set up row object
			ew_ElementsToRow(fobj);

			// Fire Form_CustomValidate event
			if (!this.Form_CustomValidate(fobj))
				return false;
	}

	// Process detail forms
	var dfs = $fobj.find("input[name='detailpage']").get();
	for (var i = 0; i < dfs.length; i++) {
		var df = dfs[i], val = df.value;
		if (val && ewForms[val])
			if (!ewForms[val].Validate())
				return false;
	}
	return true;
}

// Form_CustomValidate event
fplanoperacionesadd.Form_CustomValidate = 
 function(fobj) { // DO NOT CHANGE THIS LINE!

 	// Your custom validation code here, return false if invalid. 
 	return true;
 }

// Use JavaScript validation or not
<?php if (EW_CLIENT_VALIDATE) { ?>
fplanoperacionesadd.ValidateRequired = true;
<?php } else { ?>
fplanoperacionesadd.ValidateRequired = false; 
<?php } ?>

// Dynamic selection lists
fplanoperacionesadd.Lists["x_Plan"] = {"LinkField":"x_PlanId","Ajax":true,"AutoFill":false,"DisplayFields":["x_PlanDescripcion","","",""],"ParentFields":[],"FilterFields":[],"Options":[]};
fplanoperacionesadd.Lists["x_Destino"] = {"LinkField":"x_sucursalId","Ajax":null,"AutoFill":false,"DisplayFields":["x_sucursalNombre","","",""],"ParentFields":[],"FilterFields":[],"Options":[]};
fplanoperacionesadd.Lists["x_Chofer"] = {"LinkField":"x_ChoId","Ajax":true,"AutoFill":false,"DisplayFields":["x_ChoNombre","","",""],"ParentFields":[],"FilterFields":[],"Options":[]};
fplanoperacionesadd.Lists["x_Vehiculo"] = {"LinkField":"x_VehId","Ajax":true,"AutoFill":false,"DisplayFields":["x_VehPatente","x_VehDescripcion","",""],"ParentFields":[],"FilterFields":[],"Options":[]};

// Form object for search
</script>
<script type="text/javascript">

// Write your client script here, no need to add script tags.
</script>
<?php $Breadcrumb->Render(); ?>
<?php $planoperaciones_add->ShowPageHeader(); ?>
<?php
$planoperaciones_add->ShowMessage();
?>
<form name="fplanoperacionesadd" id="fplanoperacionesadd" class="ewForm form-horizontal" action="<?php echo ew_CurrentPage() ?>" method="post">
<input type="hidden" name="t" value="planoperaciones">
<input type="hidden" name="a_add" id="a_add" value="A">
<table class="ewGrid"><tr><td>
<table id="tbl_planoperacionesadd" class="table table-bordered table-striped">
<?php if ($planoperaciones->Fecha->Visible) { // Fecha ?>
	<tr id="r_Fecha">
		<td><span id="elh_planoperaciones_Fecha"><?php echo $planoperaciones->Fecha->FldCaption() ?></span></td>
		<td<?php echo $planoperaciones->Fecha->CellAttributes() ?>>
<span id="el_planoperaciones_Fecha" class="control-group">
<input type="text" data-field="x_Fecha" name="x_Fecha" id="x_Fecha" size="11" maxlength="50" placeholder="<?php echo $planoperaciones->Fecha->PlaceHolder ?>" value="<?php echo $planoperaciones->Fecha->EditValue ?>"<?php echo $planoperaciones->Fecha->EditAttributes() ?>>
<?php if (!$planoperaciones->Fecha->ReadOnly && !$planoperaciones->Fecha->Disabled && @$planoperaciones->Fecha->EditAttrs["readonly"] == "" && @$planoperaciones->Fecha->EditAttrs["disabled"] == "") { ?>
<button id="cal_x_Fecha" name="cal_x_Fecha" class="btn" type="button"><img src="phpimages/calendar.png" alt="<?php echo $Language->Phrase("PickDate") ?>" title="<?php echo $Language->Phrase("PickDate") ?>" style="border: 0;"></button><script type="text/javascript">
ew_CreateCalendar("fplanoperacionesadd", "x_Fecha", "%d/%m/%Y");
</script>
<?php } ?>
</span>
<?php echo $planoperaciones->Fecha->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($planoperaciones->Plan->Visible) { // Plan ?>
	<tr id="r_Plan">
		<td><span id="elh_planoperaciones_Plan"><?php echo $planoperaciones->Plan->FldCaption() ?></span></td>
		<td<?php echo $planoperaciones->Plan->CellAttributes() ?>>
<?php if ($planoperaciones->Plan->getSessionValue() <> "") { ?>
<span<?php echo $planoperaciones->Plan->ViewAttributes() ?>>
<?php echo $planoperaciones->Plan->ViewValue ?></span>
<input type="hidden" id="x_Plan" name="x_Plan" value="<?php echo ew_HtmlEncode($planoperaciones->Plan->CurrentValue) ?>">
<?php } else { ?>
<?php
	$wrkonchange = trim(" " . @$planoperaciones->Plan->EditAttrs["onchange"]);
	if ($wrkonchange <> "") $wrkonchange = " onchange=\"" . ew_JsEncode2($wrkonchange) . "\"";
	$planoperaciones->Plan->EditAttrs["onchange"] = "";
?>
<span id="as_x_Plan" style="white-space: nowrap; z-index: 8970">
	<input type="text" name="sv_x_Plan" id="sv_x_Plan" value="<?php echo $planoperaciones->Plan->EditValue ?>" size="30" placeholder="<?php echo $planoperaciones->Plan->PlaceHolder ?>"<?php echo $planoperaciones->Plan->EditAttributes() ?>>&nbsp;<span id="em_x_Plan" class="ewMessage" style="display: none"><?php echo str_replace("%f", "phpimages/", $Language->Phrase("UnmatchedValue")) ?></span>
	<div id="sc_x_Plan" style="display: inline; z-index: 8970"></div>
</span>
<input type="hidden" data-field="x_Plan" name="x_Plan" id="x_Plan" value="<?php echo ew_HtmlEncode($planoperaciones->Plan->CurrentValue) ?>"<?php echo $wrkonchange ?>>
<?php
$sSqlWrk = "SELECT `PlanId`, `PlanDescripcion` AS `DispFld` FROM `plansemanal`";
$sWhereWrk = "`PlanDescripcion` LIKE '{query_value}%'";

// Call Lookup selecting
$planoperaciones->Lookup_Selecting($planoperaciones->Plan, $sWhereWrk);
if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
$sSqlWrk .= " LIMIT " . EW_AUTO_SUGGEST_MAX_ENTRIES;
?>
<input type="hidden" name="q_x_Plan" id="q_x_Plan" value="s=<?php echo ew_Encrypt($sSqlWrk) ?>">
<script type="text/javascript">
var oas = new ew_AutoSuggest("x_Plan", fplanoperacionesadd, false, EW_AUTO_SUGGEST_MAX_ENTRIES);
oas.formatResult = function(ar) {
	var dv = ar[1];
	for (var i = 2; i <= 4; i++)
		dv += (ar[i]) ? ew_ValueSeparator(i - 1, "x_Plan") + ar[i] : "";
	return dv;
}
fplanoperacionesadd.AutoSuggests["x_Plan"] = oas;
</script>
<?php } ?>
<?php echo $planoperaciones->Plan->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($planoperaciones->Descripcion->Visible) { // Descripcion ?>
	<tr id="r_Descripcion">
		<td><span id="elh_planoperaciones_Descripcion"><?php echo $planoperaciones->Descripcion->FldCaption() ?></span></td>
		<td<?php echo $planoperaciones->Descripcion->CellAttributes() ?>>
<span id="el_planoperaciones_Descripcion" class="control-group">
<input type="text" data-field="x_Descripcion" name="x_Descripcion" id="x_Descripcion" size="100" maxlength="150" placeholder="<?php echo $planoperaciones->Descripcion->PlaceHolder ?>" value="<?php echo $planoperaciones->Descripcion->EditValue ?>"<?php echo $planoperaciones->Descripcion->EditAttributes() ?>>
</span>
<?php echo $planoperaciones->Descripcion->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($planoperaciones->Origen->Visible) { // Origen ?>
	<tr id="r_Origen">
		<td><span id="elh_planoperaciones_Origen"><?php echo $planoperaciones->Origen->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></span></td>
		<td<?php echo $planoperaciones->Origen->CellAttributes() ?>>
<span id="el_planoperaciones_Origen" class="control-group">
<select data-field="x_Origen" id="x_Origen" name="x_Origen"<?php echo $planoperaciones->Origen->EditAttributes() ?>>
<?php
if (is_array($planoperaciones->Origen->EditValue)) {
	$arwrk = $planoperaciones->Origen->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($planoperaciones->Origen->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
</span>
<?php echo $planoperaciones->Origen->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($planoperaciones->Destino->Visible) { // Destino ?>
	<tr id="r_Destino">
		<td><span id="elh_planoperaciones_Destino"><?php echo $planoperaciones->Destino->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></span></td>
		<td<?php echo $planoperaciones->Destino->CellAttributes() ?>>
<span id="el_planoperaciones_Destino" class="control-group">
<select data-field="x_Destino" id="x_Destino" name="x_Destino"<?php echo $planoperaciones->Destino->EditAttributes() ?>>
<?php
if (is_array($planoperaciones->Destino->EditValue)) {
	$arwrk = $planoperaciones->Destino->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($planoperaciones->Destino->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
<script type="text/javascript">
fplanoperacionesadd.Lists["x_Destino"].Options = <?php echo (is_array($planoperaciones->Destino->EditValue)) ? ew_ArrayToJson($planoperaciones->Destino->EditValue, 1) : "[]" ?>;
</script>
</span>
<?php echo $planoperaciones->Destino->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($planoperaciones->Chofer->Visible) { // Chofer ?>
	<tr id="r_Chofer">
		<td><span id="elh_planoperaciones_Chofer"><?php echo $planoperaciones->Chofer->FldCaption() ?></span></td>
		<td<?php echo $planoperaciones->Chofer->CellAttributes() ?>>
<span id="el_planoperaciones_Chofer" class="control-group">
<select data-field="x_Chofer" id="x_Chofer" name="x_Chofer"<?php echo $planoperaciones->Chofer->EditAttributes() ?>>
<?php
if (is_array($planoperaciones->Chofer->EditValue)) {
	$arwrk = $planoperaciones->Chofer->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($planoperaciones->Chofer->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
<?php if (AllowAdd(CurrentProjectID() . "choferes")) { ?>
&nbsp;<a id="aol_x_Chofer" class="ewAddOptLink" href="javascript:void(0);" onclick="ew_AddOptDialogShow({lnk:this,el:'x_Chofer',url:'choferesaddopt.php'});"><?php echo $Language->Phrase("AddLink") ?>&nbsp;<?php echo $planoperaciones->Chofer->FldCaption() ?></a>
<?php } ?>
<?php
$sSqlWrk = "SELECT `ChoId`, `ChoNombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `choferes`";
$sWhereWrk = "";

// Call Lookup selecting
$planoperaciones->Lookup_Selecting($planoperaciones->Chofer, $sWhereWrk);
if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
?>
<input type="hidden" name="s_x_Chofer" id="s_x_Chofer" value="s=<?php echo ew_Encrypt($sSqlWrk) ?>&amp;f0=<?php echo ew_Encrypt("`ChoId` = {filter_value}"); ?>&amp;t0=3">
</span>
<?php echo $planoperaciones->Chofer->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($planoperaciones->Vehiculo->Visible) { // Vehiculo ?>
	<tr id="r_Vehiculo">
		<td><span id="elh_planoperaciones_Vehiculo"><?php echo $planoperaciones->Vehiculo->FldCaption() ?></span></td>
		<td<?php echo $planoperaciones->Vehiculo->CellAttributes() ?>>
<span id="el_planoperaciones_Vehiculo" class="control-group">
<select data-field="x_Vehiculo" id="x_Vehiculo" name="x_Vehiculo"<?php echo $planoperaciones->Vehiculo->EditAttributes() ?>>
<?php
if (is_array($planoperaciones->Vehiculo->EditValue)) {
	$arwrk = $planoperaciones->Vehiculo->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($planoperaciones->Vehiculo->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
<?php if ($arwrk[$rowcntwrk][2] <> "") { ?>
<?php echo ew_ValueSeparator(1,$planoperaciones->Vehiculo) ?><?php echo $arwrk[$rowcntwrk][2] ?>
<?php } ?>
</option>
<?php
	}
}
?>
</select>
<?php
$sSqlWrk = "SELECT `VehId`, `VehPatente` AS `DispFld`, `VehDescripcion` AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `vehiculos`";
$sWhereWrk = "";

// Call Lookup selecting
$planoperaciones->Lookup_Selecting($planoperaciones->Vehiculo, $sWhereWrk);
if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
?>
<input type="hidden" name="s_x_Vehiculo" id="s_x_Vehiculo" value="s=<?php echo ew_Encrypt($sSqlWrk) ?>&amp;f0=<?php echo ew_Encrypt("`VehId` = {filter_value}"); ?>&amp;t0=3">
</span>
<?php echo $planoperaciones->Vehiculo->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($planoperaciones->Pedido->Visible) { // Pedido ?>
	<tr id="r_Pedido">
		<td><span id="elh_planoperaciones_Pedido"><?php echo $planoperaciones->Pedido->FldCaption() ?></span></td>
		<td<?php echo $planoperaciones->Pedido->CellAttributes() ?>>
<span id="el_planoperaciones_Pedido" class="control-group">
<input type="text" data-field="x_Pedido" name="x_Pedido" id="x_Pedido" size="15" placeholder="<?php echo $planoperaciones->Pedido->PlaceHolder ?>" value="<?php echo $planoperaciones->Pedido->EditValue ?>"<?php echo $planoperaciones->Pedido->EditAttributes() ?>>
<?php if (!$planoperaciones->Pedido->ReadOnly && !$planoperaciones->Pedido->Disabled && @$planoperaciones->Pedido->EditAttrs["readonly"] == "" && @$planoperaciones->Pedido->EditAttrs["disabled"] == "") { ?>
<button id="cal_x_Pedido" name="cal_x_Pedido" class="btn" type="button"><img src="phpimages/calendar.png" alt="<?php echo $Language->Phrase("PickDate") ?>" title="<?php echo $Language->Phrase("PickDate") ?>" style="border: 0;"></button><script type="text/javascript">
ew_CreateCalendar("fplanoperacionesadd", "x_Pedido", "%d/%m/%Y %H:%M:%S");
</script>
<?php } ?>
</span>
<?php echo $planoperaciones->Pedido->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($planoperaciones->Carga->Visible) { // Carga ?>
	<tr id="r_Carga">
		<td><span id="elh_planoperaciones_Carga"><?php echo $planoperaciones->Carga->FldCaption() ?></span></td>
		<td<?php echo $planoperaciones->Carga->CellAttributes() ?>>
<span id="el_planoperaciones_Carga" class="control-group">
<input type="text" data-field="x_Carga" name="x_Carga" id="x_Carga" size="15" placeholder="<?php echo $planoperaciones->Carga->PlaceHolder ?>" value="<?php echo $planoperaciones->Carga->EditValue ?>"<?php echo $planoperaciones->Carga->EditAttributes() ?>>
<?php if (!$planoperaciones->Carga->ReadOnly && !$planoperaciones->Carga->Disabled && @$planoperaciones->Carga->EditAttrs["readonly"] == "" && @$planoperaciones->Carga->EditAttrs["disabled"] == "") { ?>
<button id="cal_x_Carga" name="cal_x_Carga" class="btn" type="button"><img src="phpimages/calendar.png" alt="<?php echo $Language->Phrase("PickDate") ?>" title="<?php echo $Language->Phrase("PickDate") ?>" style="border: 0;"></button><script type="text/javascript">
ew_CreateCalendar("fplanoperacionesadd", "x_Carga", "%d/%m/%Y %H:%M:%S");
</script>
<?php } ?>
</span>
<?php echo $planoperaciones->Carga->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($planoperaciones->Descarga->Visible) { // Descarga ?>
	<tr id="r_Descarga">
		<td><span id="elh_planoperaciones_Descarga"><?php echo $planoperaciones->Descarga->FldCaption() ?></span></td>
		<td<?php echo $planoperaciones->Descarga->CellAttributes() ?>>
<span id="el_planoperaciones_Descarga" class="control-group">
<input type="text" data-field="x_Descarga" name="x_Descarga" id="x_Descarga" size="15" placeholder="<?php echo $planoperaciones->Descarga->PlaceHolder ?>" value="<?php echo $planoperaciones->Descarga->EditValue ?>"<?php echo $planoperaciones->Descarga->EditAttributes() ?>>
<?php if (!$planoperaciones->Descarga->ReadOnly && !$planoperaciones->Descarga->Disabled && @$planoperaciones->Descarga->EditAttrs["readonly"] == "" && @$planoperaciones->Descarga->EditAttrs["disabled"] == "") { ?>
<button id="cal_x_Descarga" name="cal_x_Descarga" class="btn" type="button"><img src="phpimages/calendar.png" alt="<?php echo $Language->Phrase("PickDate") ?>" title="<?php echo $Language->Phrase("PickDate") ?>" style="border: 0;"></button><script type="text/javascript">
ew_CreateCalendar("fplanoperacionesadd", "x_Descarga", "%d/%m/%Y %H:%M:%S");
</script>
<?php } ?>
</span>
<?php echo $planoperaciones->Descarga->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($planoperaciones->Retorno->Visible) { // Retorno ?>
	<tr id="r_Retorno">
		<td><span id="elh_planoperaciones_Retorno"><?php echo $planoperaciones->Retorno->FldCaption() ?></span></td>
		<td<?php echo $planoperaciones->Retorno->CellAttributes() ?>>
<span id="el_planoperaciones_Retorno" class="control-group">
<input type="text" data-field="x_Retorno" name="x_Retorno" id="x_Retorno" size="15" placeholder="<?php echo $planoperaciones->Retorno->PlaceHolder ?>" value="<?php echo $planoperaciones->Retorno->EditValue ?>"<?php echo $planoperaciones->Retorno->EditAttributes() ?>>
<?php if (!$planoperaciones->Retorno->ReadOnly && !$planoperaciones->Retorno->Disabled && @$planoperaciones->Retorno->EditAttrs["readonly"] == "" && @$planoperaciones->Retorno->EditAttrs["disabled"] == "") { ?>
<button id="cal_x_Retorno" name="cal_x_Retorno" class="btn" type="button"><img src="phpimages/calendar.png" alt="<?php echo $Language->Phrase("PickDate") ?>" title="<?php echo $Language->Phrase("PickDate") ?>" style="border: 0;"></button><script type="text/javascript">
ew_CreateCalendar("fplanoperacionesadd", "x_Retorno", "%d/%m/%Y %H:%M:%S");
</script>
<?php } ?>
</span>
<?php echo $planoperaciones->Retorno->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($planoperaciones->Observacion->Visible) { // Observacion ?>
	<tr id="r_Observacion">
		<td><span id="elh_planoperaciones_Observacion"><?php echo $planoperaciones->Observacion->FldCaption() ?></span></td>
		<td<?php echo $planoperaciones->Observacion->CellAttributes() ?>>
<span id="el_planoperaciones_Observacion" class="control-group">
<input type="text" data-field="x_Observacion" name="x_Observacion" id="x_Observacion" size="150" maxlength="250" placeholder="<?php echo $planoperaciones->Observacion->PlaceHolder ?>" value="<?php echo $planoperaciones->Observacion->EditValue ?>"<?php echo $planoperaciones->Observacion->EditAttributes() ?>>
</span>
<?php echo $planoperaciones->Observacion->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($planoperaciones->MostrarObservacion->Visible) { // MostrarObservacion ?>
	<tr id="r_MostrarObservacion">
		<td><span id="elh_planoperaciones_MostrarObservacion"><?php echo $planoperaciones->MostrarObservacion->FldCaption() ?></span></td>
		<td<?php echo $planoperaciones->MostrarObservacion->CellAttributes() ?>>
<span id="el_planoperaciones_MostrarObservacion" class="control-group">
<div id="tp_x_MostrarObservacion" class="<?php echo EW_ITEM_TEMPLATE_CLASSNAME; ?>"><input type="checkbox" name="x_MostrarObservacion[]" id="x_MostrarObservacion[]" value="{value}"<?php echo $planoperaciones->MostrarObservacion->EditAttributes() ?>></div>
<div id="dsl_x_MostrarObservacion" data-repeatcolumn="5" class="ewItemList">
<?php
$arwrk = $planoperaciones->MostrarObservacion->EditValue;
if (is_array($arwrk)) {
	$armultiwrk= explode(",", strval($planoperaciones->MostrarObservacion->CurrentValue));
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = "";
		$cnt = count($armultiwrk);
		for ($ari = 0; $ari < $cnt; $ari++) {
			if (strval($arwrk[$rowcntwrk][0]) == trim(strval($armultiwrk[$ari]))) {
				$selwrk = " checked=\"checked\"";
				if ($selwrk <> "") $emptywrk = FALSE;
				break;
			}
		}

		// Note: No spacing within the LABEL tag
?>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 1) ?>
<label class="checkbox"><input type="checkbox" data-field="x_MostrarObservacion" name="x_MostrarObservacion[]" id="x_MostrarObservacion_<?php echo $rowcntwrk ?>[]" value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?><?php echo $planoperaciones->MostrarObservacion->EditAttributes() ?>><?php echo $arwrk[$rowcntwrk][1] ?></label>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 2) ?>
<?php
	}
}
?>
</div>
</span>
<?php echo $planoperaciones->MostrarObservacion->CustomMsg ?></td>
	</tr>
<?php } ?>
</table>
</td></tr></table>
<?php
	if (in_array("pedidoplan", explode(",", $planoperaciones->getCurrentDetailTable())) && $pedidoplan->DetailAdd) {
?>
<?php include_once "pedidoplangrid.php" ?>
<?php } ?>
<button class="btn btn-primary ewButton" name="btnAction" id="btnAction" type="submit"><?php echo $Language->Phrase("AddBtn") ?></button>
</form>
<script type="text/javascript">
fplanoperacionesadd.Init();
<?php if (EW_MOBILE_REFLOW && ew_IsMobile()) { ?>
ew_Reflow();
<?php } ?>
</script>
<?php
$planoperaciones_add->ShowPageFooter();
if (EW_DEBUG_ENABLED)
	echo ew_DebugMsg();
?>
<script type="text/javascript">

// Write your table-specific startup script here
// document.write("page loaded");

</script>
<?php include_once "footer.php" ?>
<?php
$planoperaciones_add->Page_Terminate();
?>
